package com.wzy.pcwzy.weight;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import java.text.DecimalFormat;
import java.text.NumberFormat;

//import android.icu.text.DecimalFormat;
//import android.icu.text.NumberFormat;
/**
 * Created by PC WZY on 2017/9/14.
 */

public class ResultActivity extends Activity{
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        /*加载content.xml*/
        setContentView(R.layout.content_result);
        /*取得Intent中的bundle对象*/
        Bundle bundle = this.getIntent().getExtras();
        /*获取Bundle中对象的数据*/
        String sex = bundle.getString("sex");
        double height = bundle.getDouble("height");
        /*判定性别*/
        String setText = "";
        if (sex.equals("M"))
            setText = "男";
        else  setText = "女";
        /*取得标准体重*/
        String weight = this.getWeight(sex,height);
        /*输出文字*/
        TextView tv1 = (TextView)findViewById(R.id.text1);
        tv1.setText("你是一位"+setText+"\n你的身高是"+height+ "公分\n你的标准体重是"+weight+"公斤");
    }
    private String getWeight(String sex ,Double height){
        String weight= "";
        if (sex.equals("M"))
            weight = format((height-80)*0.7);
        else
            weight = format((height-70)*0.6);
        return  weight;
    }
    private  String format(double num){
        NumberFormat formatter = new DecimalFormat("0.00");
        String s = formatter.format(num);
        return s;
    }
}
